export default function createStatementData(invoice, palys) {
    const result = {}
    result.customer = invoice.customer
    result.performances = invoice.performances.map(enrichPerformance)
    result.totalAmount = totalAmount(result)
    result.totalVolumeCredits = totalVolumeCredits(result)
    return result;

    function enrichPerformance(aPerformance) {
        const calculator = createPerformanceCalculator(aPerformance, playFor(aPerformance));
        const assign = Object.assign({}, aPerformance);
        result.play = calculator.play;
        result.amount = calculator.amount;
        result.volumeCredits = calculator.volumeCredits
        return result;
    }

    function playFor(aPerformance) {

    }

    function totalAmount(data) {

    }

    function totalVolumeCredits(data) {

    }
}

class PerformanceCalculator {
    constructor(performance, play) {
        this.performance = performance
        this.play = play
    }

    get amount() {
        throw new Error("subClass responsibility")
    }

    get volumeCredits() {
        return Math.max(this.performance.audience - 30, 0)
    }
}

function createPerformanceCalculator(aPerformance, aPlay) {
    switch (aPlay.type) {
        case "tragedy":
            return new TragedyCalculator(aPerformance, aPlay)
        case "comedy":
            return new ComedyCalculator(aPerformance, aPlay)
        default:
            throw new Error("unknown type")
    }
}

class TragedyCalculator extends PerformanceCalculator {
    get amount() {
        let result = 4000;
        if (this.performance.audience > 30) {
            result += 1000 * (this.performance.audience - 30);
        }
        return result;
    }
}

class ComedyCalculator extends PerformanceCalculator {
    get amount() {
        let result = 4000;
        if (this.performance.audience > 30) {
            result += 1000 * (this.performance.audience - 30);
        }
        return result;
    }

    get volumeCredits() {
        return Math.max(this.performance.audience - 30, 0)
    }
}